clc;
clearvars;
rng('shuffle')
% rng('default')
ObservDataP1=load('Data\HumanData_KonovalovDataPart1.mat');
ObservDataP2=load('Data\HumanData_KonovalovDataPart2.mat');
KovonoloveFitedData=xlsread('..\FromKonovalov\ws1.xlsx');
BarGazeData=xlsread('..\FromKonovalov\GazeData.xlsx');
GazeData=load('Data\HumanData_KonovalovGazeData.mat');
% rng('default')
FeaturesIndex={ [1:27,73:78,83:88]          % No Confidence
                1:27                        % No Fitting No Confidence
                [86,83,84,87,1,77,78,73];}; % Subset2 FrwSlc ConfExc

%% 
ExcludID=[30,31];

KovonoloveFitedData(ExcludID,:)=[];

Fields= fieldnames(GazeData);
for i=1:length(Fields)
    GazeData.(Fields{i})(ExcludID,:)=[];
end

% Data.BestFittedW(ExcludID,:)=[];
% Data.Features(ExcludID,:)=[];
% Data.FittedW(ExcludID,:)=[];
% Data.SNum=Data.SNum-length(ExcludID);

ObservDataP1.ASARCMat(:,:,ExcludID)=[];
ObservDataP2.ASARCMat(:,:,ExcludID)=[];
%%
BasePlotFileName='Plots\HumanData_Konovalov_Fig';
SavePlots=0;
TextSize=14;
Fig.TextSize=14;
%% Index
WValuesKov=KovonoloveFitedData(:,2);
MedianWKov=median(WValuesKov);
KovLabel=1*(WValuesKov<=MedianWKov)+2*(WValuesKov>MedianWKov); % 1. MF 2.MB
MBGroup_Kov_Pstay_P1=ParallExtractDawPStay(ObservDataP1,KovLabel==2);
MFGroup_Kov_Pstay_P1=ParallExtractDawPStay(ObservDataP1,KovLabel==1);
MBGroup_Kov_Pstay_P2=ParallExtractDawPStay(ObservDataP2,KovLabel==2);
MFGroup_Kov_Pstay_P2=ParallExtractDawPStay(ObservDataP2,KovLabel==1);

%% Figure 12
Fig.YLim=[0.42,1];
Fig.Fig=1;
Fig.AddLegend=false;
Fig.Position=[40,40,800,350];
Fig.SubFig={1,2,2};
Fig.Title='MB By Fitting';
Fig.AddLegend=false;
PlotPStay(MBGroup_Kov_Pstay_P1,Fig);
legend({'Common','Rare'},'position',[0.85,0.915,0.1451,0.0815])
Fig.SubFig={1,2,1};
Fig.Title='MF By Fitting';
PlotPStay(MFGroup_Kov_Pstay_P1,Fig);

subplot(1,2,1);
if SavePlots
    FileName=[BasePlotFileName,'11_PStayPart1Total']; %#ok<*UNRCH>
    saveas(gcf,[FileName,'.jpg']);
    saveas(gcf,[FileName,'.emf']);
end

%%
Fig.Fig=2;
Fig.YLim=[0.42,1];
Fig.AddLegend=false;
Fig.Position=[40,40,1400,650];

Index=find(KovLabel==2);

for i=1:21
    Pstay=ParallExtractDawPStay(ObservDataP1,Index(i));
    Fig.SubFig={3,7,i};
    Fig.Title=num2str(Index(i));
    PlotPStay(Pstay,Fig);
end

%%
Fig.Fig=4;
Fig.YLim=[0.42,1];
Fig.AddLegend=false;
Fig.Position=[40,40,1400,650];

Index=find(KovLabel==1);

for i=1:21
    Pstay=ParallExtractDawPStay(ObservDataP1,Index(i));
    Fig.SubFig={3,7,i};
    Fig.Title=num2str(Index(i));
    PlotPStay(Pstay,Fig);
end
clear Fig
Fig.Fig=5;
Pstay=ParallExtractDawPStay(ObservDataP1,Index(22));
Fig.Title=num2str(Index(22));
PlotPStay(Pstay,Fig);
%%
clear Fig
Fig.Fig=6;
Fig.YLim=[0.42,1];
Fig.AddLegend=false;
Fig.Position=[40,40,1400,650];

Index=[2,13,29,33,40,41];

Pstay=ParallExtractDawPStay(ObservDataP1,Index);
Fig.SubFig={1,2,1};
PlotPStay(Pstay,Fig);
title('MB')

Index=[11,1,17,20,37,38,43];

Pstay=ParallExtractDawPStay(ObservDataP1,Index);
Fig.SubFig={1,2,2};
PlotPStay(Pstay,Fig);
title('MF')